package com.ls.controller;

import com.ls.pojo.Device;
import com.ls.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @RequestMapping("/list")
    public String getDeviceAll(Model model){
       List<Device> list= deviceService.getDeviceAll();
       model.addAttribute("list",list);
        return "list";
    }


    @RequestMapping("/add")
    public String addDevice(Device device,Model model){
        int ret=deviceService.addDevice(device);
        model.addAttribute("msg",ret==1 ? "添加成功":"添加失败");
        return "redirect:/list";
    }

    @RequestMapping("/update")
    public String updateDevice(Integer id,Integer status,Model model){
        int ret=deviceService.updateDevice(id,status);
        model.addAttribute("msg",ret==1 ? "修改成功":"修改失败");
        return "redirect:/list";
    }
}
